import { Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { DataManager } from "../Framework/Managers/DataManager";
import PrefsManager from "../Framework/Managers/PrefsManager";
import { UIManager } from "../Framework/Managers/UIManager";
import { ZTool } from "../Framework/Utils/ZTool";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FreeRewardPanel extends cc.Component {

    Show() {
    }

    OnButtonClick(event: cc.Event) {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);

        switch (event.target.name) {
            case "Mask":
            case "CloseButton":
                UIManager.Instance.HidePanel(Constant.Panel.FreeRewardPanel);
                break;
            case "Button":
                if (PrefsManager.GetBool(Constant.Key.FreeReward)) {
                    UIManager.ShowTip("已领取过");
                    return;
                }
                if (DataManager.JunXuItems.find(e => e.Name == "RPK16-神秘图腾")) {
                    let data = ZTool.DeepCopy(DataManager.JunXuItems.find(e => e.Name == "RPK16-神秘图腾"));
                    DataManager.AddPlayerItem(data);
                    UIManager.Instance.HidePanel(Constant.Panel.FreeRewardPanel);
                    UIManager.Instance.ShowPanel(Constant.Panel.RewardPanel, [data])
                    PrefsManager.SetBool(Constant.Key.FreeReward, true);
                }
                break;

        }
    }
}
